<template>
	<view class="mainpadding">
		<textarea class="textarea ffffff radius" placeholder="请输入备注内容" v-model="remarks"></textarea>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submitadd()" v-if="type==1">确认添加</view>
			<view class="bigbtn" @click="submitedit()" v-if="type==2">保存</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: 1, //1添加，2编辑
				remarks: "",
				listid: ""
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.type = options.type
			if (this.type == 2) {
				this.getDetail()
			}

		},
		methods: {
			getDetail() {
				httpRequest.request('/api/admintask/taskRemarksDetail', 'GET', {
					id: this.listid,
				}).then(res => {
					this.remarks = res.data.remarks
				})
			},
			submitadd() { //添加
				if (this.remarks == "") {
					httpRequest.toast("请输入备注内容")
					return false
				}
				httpRequest.request('/api/admintask/addTaskRemarks', 'GET', {
					task_id: this.listid,
					remarks: this.remarks
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			},
			submitedit() { //编辑
				if (this.name == "") {
					httpRequest.toast("请输入备注内容")
					return false
				}
				httpRequest.request('/api/admintask/editTaskRemarks', 'GET', {
					id: this.listid,
					remarks: this.remarks
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.textarea {
		box-sizing: border-box;
		padding: 30rpx;
		width: 100%;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}
</style>